# This file is part of Sonedyan.
#
# Sonedyan is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public
# License as published by the Free Software Foundation;
# either version 3 of the License, or (at your option) any
# later version.
#
# Sonedyan is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
# PURPOSE.  See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public.
# If not, see <http://www.gnu.org/licenses/>.
#
# Copyright (C) 2009-2012 Jimmy Dubuisson <jimmy.dubuisson@gmail.com>

# get the correlation graph density depending on the normalized temperature
library(igraph)

cormat <- read.table("cormat_1000x1000_v1.csv", header = TRUE)
id <- diag(rep(1,1000))

density.undirected <- function(g)
{
	return (length(E(g))/ (length(V(g)) * (length(V(g)) - 1) / 2))
}

getDensity <- function(e)
{
	cormat1a <- cormat - diag(rep(1, 1000))
	cormat1a[cormat1a < e] <- -1
	cormat1a[cormat1a >= e] <- 1
	cormat1a[cormat1a == -1] <- 0
	g <- graph.adjacency(cormat1a, mode="min")
	return(density.undirected(g))
}

for (i in seq(-1,0, by=0.01))
{
	print(paste(i, " ", getDensity(i)))
}


